* @param string|bool $error False if no error expected
*/
public function testAssert( $registered, $rights, $assert, $error ) {
- $user = new User();
if ( $registered ) {
- $user->setId( 1 );
+ $user = $this->getMutableTestUser()->getUser();
+ $user->load(); // load before setting mRights
+ } else {
+ $user = new User();
}
$user->mRights = $rights;
try {
], null, null, $user );
$this->assertFalse( $error ); // That no error was expected
} catch ( ApiUsageException $e ) {
- $this->assertTrue( self::apiExceptionHasCode( $e, $error ) );
+ $this->assertTrue( self::apiExceptionHasCode( $e, $error ),
+ "Error '{$e->getMessage()}' matched expected '$error'" );
}
}
$priv = TestingAccessWrapper::newFromObject( $api );
$priv->mInternalMode = false;
- $module = $this->getMockBuilder( 'ApiBase' )
+ $module = $this->getMockBuilder( ApiBase::class )
->setConstructorArgs( [ $api, 'mock' ] )
->setMethods( [ 'getConditionalRequestData' ] )
->getMockForAbstractClass();
$priv = TestingAccessWrapper::newFromObject( $api );
$priv->mInternalMode = false;
- $module = $this->getMockBuilder( 'ApiBase' )
+ $module = $this->getMockBuilder( ApiBase::class )
->setConstructorArgs( [ $api, 'mock' ] )
->setMethods( [ 'getConditionalRequestData' ] )
->getMockForAbstractClass();
)->inLanguage( 'en' )->useDatabase( false )->text();
$dbex = new DBQueryError(
- $this->createMock( 'IDatabase' ),
+ $this->createMock( \Wikimedia\Rdbms\IDatabase::class ),
'error', 1234, 'SELECT 1', __METHOD__ );
$dbtrace = wfMessage( 'api-exception-trace',
get_class( $dbex ),
MWExceptionHandler::getRedactedTraceAsString( $dbex )
)->inLanguage( 'en' )->useDatabase( false )->text();
+ MediaWiki\suppressWarnings();
+ $usageEx = new UsageException( 'Usage exception!', 'ue', 0, [ 'foo' => 'bar' ] );
+ MediaWiki\restoreWarnings();
+
$apiEx1 = new ApiUsageException( null,
StatusValue::newFatal( new ApiRawMessage( 'An error', 'sv-error1' ) ) );
TestingAccessWrapper::newFromObject( $apiEx1 )->modulePath = 'foo+bar';
]
],
[
- new UsageException( 'Usage exception!', 'ue', 0, [ 'foo' => 'bar' ] ),
+ $usageEx,
[ 'existing-error', 'ue' ],
[
'warnings' => [